package ltd.sshine.tracking.web.validator;


import jakarta.validation.ConstraintValidator;
import jakarta.validation.ConstraintValidatorContext;

public class NumberPatternValidator implements ConstraintValidator<NumberPattern, Number> {

    private String regexp;
    @Override
    public void initialize(NumberPattern constraintAnnotation) {
        this.regexp = constraintAnnotation.regexp();
    }
    @Override
    public boolean isValid(Number number, ConstraintValidatorContext constraintValidatorContext) {
        if (number!=null){
          return number.toString().matches(regexp);
        }
        return true;
    }
}
